#include "CampaignSetting.h"

#define GROUP_ID(value) QString("%1.%2").arg(name()).arg(value)

namespace
{
const char* TR_CONTEXT = "CampaignSetting";
QString ATTRIBUTE_GROUP = QT_TRANSLATE_NOOP(TR_CONTEXT, "Attributes");
QString SKILL_GROUP = QT_TRANSLATE_NOOP(TR_CONTEXT, "Skills");
QString FEAT_GROUP = QT_TRANSLATE_NOOP(TR_CONTEXT, "Feats");
QString SPECIAL_GROUP = QT_TRANSLATE_NOOP(TR_CONTEXT, "Special Abilities");
QString BONUS_GROUP = QT_TRANSLATE_NOOP(TR_CONTEXT, "Bonuses");


}

CampaignSetting::CampaignSetting(QObject *parent)
    : QObject(parent)
{
    m_rootItem = new ItemRoot(tr("New Campaign Setting"), this);
    m_itemModel = new ItemModel(m_rootItem, this);
}



CampaignSetting::CampaignSetting(ItemRoot *rootItem, QObject *parent)
    : QObject(parent)
{
    m_rootItem = rootItem;
    if (m_rootItem) m_rootItem->setParent(this);
    m_itemModel = new ItemModel(m_rootItem, this);
}



ItemModel* CampaignSetting::model() const
{
    return m_itemModel;
}


ItemRoot* CampaignSetting::root() const
{
    return m_rootItem;
}

QString CampaignSetting::name() const
{
    return m_rootItem->name();
}


QStringList CampaignSetting::attributes() const
{

}


QStringList CampaignSetting::skills() const
{
}


QString CampaignSetting::skillAttribute(const QString& skill) const
{
}


QStringList CampaignSetting::skillSynergies(const QString& skill) const
{
}

QStringList CampaignSetting::feats() const
{
}


QStringList CampaignSetting::featRequirements()
{
}

QStringList CampaignSetting::specials() const
{
}


QStringList CampaignSetting::bonusTypes() const
{
}

QVariantList CampaignSetting::bonusLevels(const QString& bonusType) const
{
}

QStringList CampaignSetting::bonuses(const QString& bonusType, const QString& bonusLevel)
{
}


void CampaignSetting::setName(const QString& name)
{
    m_rootItem->setData(AbstractItem::NameData, name);
}


void CampaignSetting::addAttribute(const QString& name)
{
    QModelIndex     searchIndex = m_itemModel->index(0, AbstractItem::IdData, QModelIndex());
    QModelIndexList foundIndexes = m_itemModel->match(searchIndex,
                                                      Qt::EditRole,
                                                      GROUP_ID(ATTRIBUTE_GROUP),
                                                      1,
                                                      Qt::MatchExactly);
    QModelIndex     groupIndex;
    if (!foundIndexes.isEmpty()) groupIndex = foundIndexes.first();

    if (!groupIndex.isValid())
    {
        int row = m_itemModel->rowCount();
        m_itemModel->insertRow(row, QModelIndex());
        groupNameIndex = m_itemModel->index(row, AbstractItem::NameData, QModelIndex());
        m_itemModel->setData(groupNameIndex, ATTRIBUTE_GROUP);

        groupIndex = groupNameIndex.sibling(row, AbstractItem::IdData);
    }

    if (!groupIndex.isValid()) return;

    int row = m_itemModel->rowCount(groupIndex);
    m_itemModel->insertRow(row, groupIndex);

    QModelIndex index = m_
    m_itemModel->setData()

}

void CampaignSetting::addSkill(const QString& name)
{
}

void CampaignSetting::addFeat(const QString& name)
{
}

void CampaignSetting::addSpecial(const QString& name)
{
}

void CampaignSetting::addBonusType(const QString& name)
{
}

void CampaignSetting::addBonusLevel(const QString& bonusType, const QVariant& bonusLevel)
{
}

